import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

if __name__ == '__main__':
    """宣讲会举办数量占比图（按照单位性质分类）"""
    df = pd.read_csv('../teachin_20241101_20231101.csv')
    df['date'] = df['date'].apply(lambda x: x.split(' ')[0])
    df['date'] = pd.to_datetime(df['date'])
    df['week'] = df['date'] - pd.to_timedelta(df['date'].dt.weekday, unit='D')
    df['week'] = df['week'].dt.date
    df = df[df['date'] >= '2023-11-01']
    df = df[df['date'] < '2024-11-01']
    # df = df[df['industry'].isin(['信息传输、软件和信息技术服务业'])]
    teachins, labels = zip(*[(data.shape[0], property) for property, data in df.groupby('property')])
    teachins, labels = zip(*sorted(zip(teachins, labels), key=lambda x: x[0], reverse=True))
    plt.figure(figsize=(10, 5))
    matplotlib.rcParams['font.sans-serif'] = 'KaiTi'
    plt.pie(x=teachins, labels=teachins, autopct='%1.1f%%')
    plt.title('宣讲会举办数量占比图')
    plt.legend(labels=labels, bbox_to_anchor=(1, 1))
    plt.show()
